package com.choosefine.it.team.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.choosefine.it.base.BaseController;
import com.choosefine.it.base.dto.PageDTO;
import com.choosefine.it.common.def.CommonConstant;
import com.choosefine.it.team.model.vo.FinancialSumVO;
import com.choosefine.it.team.service.TeamProjectSituationService;
import com.google.gson.Gson;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 *控制台-项目管理-班组资金
 *
 * @author 廖仉根
 * @date 2016-12-9 下午5:17:35
 */
@Api(value="项目管理-班组相关接口",description="廖仉根")
@RestController
@RequestMapping("/")
public class TeamProjectSituationController extends BaseController {
	@Autowired
	private TeamProjectSituationService teamProjectSituationService;
	
	private Gson gson = new Gson();
	

	
	/**
	 * 项目下的班组列表及金额
	 * 
	 * situation/list/{userCode}?pageNum={pageNum}&pageSize={pageSize}&search={search}&projectCode={projectCode}
	 *
	 * @Author：liaozhanggen
	 * @Create Date：2017年3月6日
	 * @param：....
	 * @return：String
	 */
	@GetMapping("situation/list/{userCode}")
	public String findProjectTeamListCapital(
			@RequestParam(name="pageNum",defaultValue="0") int pageNum,
			@RequestParam(name="pageSize",defaultValue="10") int pageSize,
			@RequestParam(name="search",required=false) String search,
			@RequestParam(name="projectCode") String projectCode,
			@PathVariable(name="userCode") String userCode){
		
		Map<String, Object> param = new HashMap<>();
		param.put(CommonConstant.PROJECT_CODE, projectCode);
		param.put(CommonConstant.SEARCH, search);
		param.put(CommonConstant.USER_CODE, userCode);
		return responseSuccess(teamProjectSituationService.findProjectTeamCapitalList(param,new PageDTO(pageNum, pageSize)));
	}
	
	/**
     * 项目下的班组数、及各班组分包金额总额 内部支撑App业务调用
     * 
     * @author liaozhanggen 2016年12月31日
     */
	@ApiOperation(value="项目下的班组数、及各班组分包金额总额 内部支撑App业务调用")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "constructUserCode", value = "承建单位租房编号", dataType = "String", required = true, paramType = "query") })
	@GetMapping("project/finance/total/{projectCode}")
    public String findProjectFinanceTotal(
    			@PathVariable(name="projectCode") String projectCode,
    			@RequestParam(name="constructUserCode") String constructUserCode){
		FinancialSumVO financialSumVO = teamProjectSituationService.findProjectFinanceTotalByProjectCode(projectCode,constructUserCode);
		return gson.toJson(financialSumVO);
	}
}
